package logic

import (
	"context"
	"order_srv/models"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *GoodsAddLogic) GoodsAdd(in *order.GoodsAddRequest) (*order.GoodsAddResponse, error) {
	goods := models.Good{
		GoodsTitle:  in.GoodsTitle,
		GoodsImage:  in.GoodsImage,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStock:  in.GoodsStock,
		GoodsStatus: in.GoodsStatus,
	}

	if err := goods.Create(); err != nil {
		logx.Info("商品发布失败", err)
		return nil, err
	}

	return &order.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
